#pragma once

#include "fxcc/core/pch.h"
#include "fxcc/core/Base.h"
#include "fxcc/yml/Serializer.h"

namespace fxcc
{
    namespace graph
    {
        namespace common
        {
            inline void Load(const aiColor3D &source, glm::vec3 &target)
            {
                target.x = source.r;
                target.y = source.g;
                target.z = source.b;
            };

            inline void Load(const aiColor4D &source, glm::vec4 &target)
            {
                target.x = source.r;
                target.y = source.g;
                target.z = source.b;
                target.w = source.a;
            };

            inline void Load(const aiVector3D &source, glm::vec3 &target)
            {
                target.x = source.x;
                target.y = source.y;
                target.z = source.z;
            };
            inline void Load(const aiVector2D &source, glm::vec2 &target)
            {
                target.x = source.x;
                target.y = source.y;
            };

            inline void Load(const aiQuaternion &source, glm::quat &target)
            {
                target.x = source.x;
                target.y = source.y;
                target.z = source.z;
                target.w = source.w;
            };
            inline void Load(const aiMatrix4x4 &source, glm::mat4 &target)
            {
                memcpy(&target, &source, sizeof(glm::mat4));
                target = glm::transpose(target);
            };


            inline std::string SanitizeFileName(const std::string& input, char replacement = '_') {
                static const std::unordered_set<char> invalidChars = {
                    '<', '>', ':', '"', '/', '\\', '|', '?', '*'
                };

                std::string result = input;
                for (char& c : result) {
                    if (invalidChars.count(c)) {
                        c = replacement;
                    }
                }
                return result;
            }

            inline void Load(const aiString& source, std::string& target)
            {
                if (source.C_Str())
                {
                    target = SanitizeFileName(source.C_Str());
                }

            }
        }
    }
}